package com.igeek.ch02.utils;

import org.apache.commons.beanutils.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//Date转字符型封装的包，可以直接被引用
public class DateConverterUtils implements Converter {

    @Override
    public Object convert(Class aClass, Object o) {
        if(o instanceof String){
            String str = (String)o;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = sdf.parse(str);
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
